home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Lines Curves and Area Fills / RoundRect / RoundRect.cs next >
Encoding:
Text File  |  2001-01-15  |  1.9 KB  |  52 lines

  1. //----------------------------------------
  2. // RoundRect.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class RoundRect: PrintableForm
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new RoundRect());
  13.      }
  14.      public RoundRect()
  15.      {
  16.           Text = "Rounded Rectangle";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           RoundedRectangle(grfx, Pens.Red, 
  21.                            new Rectangle(0, 0, cx - 1, cy - 1),
  22.                            new Size(cx / 5, cy / 5));
  23.      }
  24.      void RoundedRectangle(Graphics grfx, Pen pen, Rectangle rect, Size size)
  25.      {
  26.           grfx.DrawLine(pen, rect.Left  + size.Width / 2, rect.Top,
  27.                              rect.Right - size.Width / 2, rect.Top);
  28.  
  29.           grfx.DrawArc(pen, rect.Right - size.Width, rect.Top, 
  30.                             size.Width, size.Height, 270, 90);
  31.  
  32.           grfx.DrawLine(pen, rect.Right, rect.Top + size.Height / 2,
  33.                              rect.Right, rect.Bottom - size.Height / 2);
  34.  
  35.           grfx.DrawArc(pen, rect.Right - size.Width, 
  36.                             rect.Bottom - size.Height,
  37.                             size.Width, size.Height, 0, 90);
  38.  
  39.           grfx.DrawLine(pen, rect.Right - size.Width / 2, rect.Bottom,
  40.                              rect.Left + size.Width / 2, rect.Bottom);
  41.  
  42.           grfx.DrawArc(pen, rect.Left, rect.Bottom - size.Height,
  43.                             size.Width, size.Height, 90, 90);
  44.  
  45.           grfx.DrawLine(pen, rect.Left, rect.Bottom - size.Height / 2,
  46.                              rect.Left, rect.Top + size.Height / 2);
  47.  
  48.           grfx.DrawArc(pen, rect.Left, rect.Top,
  49.                             size.Width, size.Height, 180, 90);
  50.      }
  51. }
  52.